Skip to main content
Access via:io.bus

2 Methods

publish()⚓︎

(topic: string, data: object, options?: MessageOptions) => void

Publishes the provided data on a specific topic. An optional object can be provided to publish a message to specific peers.

Parameters (3)

Name Type Required Description
topic⚓︎ string

Topic on which to publish the message.

data⚓︎ object

Data to publish.

options⚓︎ MessageOptions x

An optional object with message options.

Example

io.bus.publish("prices", { RIC: "VOD.L", price: 21.2 });

subscribe()⚓︎

(topic: string, callback: (data: object, topic: string, source: Instance) => void, options?: MessageOptions) => Promise<Subscription>

Subscribe for receiving data published on specific topic on the message bus. The provided callback will be invoked for each received message. An optional object can be provided to receive messages published only by specific peers.

Returns a Promise which resolves if the subscription is successful. The Promise resolves with a subscription object which can be used to unsubscribe and stop receiving messages.

Parameters (3)

Name Type Required Description
topic⚓︎ string

Topic to which to subscribe.

callback⚓︎ (data: object, topic: string, source: Instance) => void

Function that will handle the received data.

options⚓︎ MessageOptions x

An optional object with message options.

Example

io.bus.subscribe("prices", function (data, topic, source) {
    console.log(data, topic, source);
});